package Year22_Month03.day08;

import java.util.Scanner;

public class Main4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int[] arr = new int[size];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
        int sum = arr[0];
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            sum = getMax(arr[i] + sum,arr[i]);
            if(sum >= max){
                max = sum;
            }
        }
        System.out.println(max);
    }
    public static int getMax(int a,int b){
        return a > b ? a : b;
    }
}
